package com.pshcp.patient.api;

import com.framework.base.PageList;
import com.framework.base.ResultBuilder;
import com.framework.base.ResultDTO;
import com.framework.exception.BizException;
import com.framework.logaop.Log;
import com.framework.logaop.LogSourceEnum;
import com.framework.logaop.LogTypeEnum;
import com.framework.tool.CommonTool;
import com.pshcp.domain.model.PatientReserveRecord;
import com.pshcp.domain.vo.PatientReserveRecordVO;
import com.pshcp.patient.domain.searchreserve.ReserveDetailAO;
import com.pshcp.patient.domain.searchreserve.ReserveListAO;
import com.pshcp.patient.tool.SearchReserveTools;
import com.pshcp.service.PatientReserveRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = {"患者端-查询-预约查询"})
@Slf4j
@RestController
@RequestMapping("/api/patient/searchReserve")
public class SearchReserveAPI {

    @Autowired
    private PatientReserveRecordService reserveRecordService;

    @ApiOperation("预约列表")
    @Log(source = LogSourceEnum.PATIENT_APP, type = LogTypeEnum.SELECT, desc = "预约列表")
    @PostMapping("/list")
    public ResultDTO<PageList<PatientReserveRecordVO>> list(@RequestBody ReserveListAO listAO) throws BizException {

        PageList<PatientReserveRecord> pageList = reserveRecordService.list(SearchReserveTools.buildDTO(listAO));

        return ResultBuilder.success(CommonTool.buildPageList(pageList, PatientReserveRecordVO.class));
    }

    @ApiOperation("预约详情")
    @Log(source = LogSourceEnum.PATIENT_APP, type = LogTypeEnum.SELECT, desc = "预约详情")
    @PostMapping("/detail")
    public ResultDTO<PatientReserveRecordVO> detail(@RequestBody ReserveDetailAO detailAO) throws BizException {

        PatientReserveRecord reserveRecord = reserveRecordService.findById(detailAO.getId());

        return ResultBuilder.success(CommonTool.copyProperties(reserveRecord, PatientReserveRecordVO.class));
    }

}
